using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
using DG.Tweening;

public class FadableSpriteShape : MonoBehaviour
{
    private SpriteShapeRenderer _renderer;

    private Color _transparent;
    private Color _color;


    // Start is called before the first frame update
    void Awake()
    {
        _renderer = GetComponent<SpriteShapeRenderer>();

        _color = _renderer.color;
        _transparent = _renderer.color;
        _transparent.a = 0f;
    }

    public void FadeIn()
    {
        StartCoroutine(DOFadeIn());
    }

    private IEnumerator DOFadeIn()
    {
        _renderer.color = _transparent;
        float y = transform.position.y;
        transform.position += (Vector3)Vector2.down * 1f;

        DOTween.To(() => _renderer.color,
                   (color) => _renderer.color = color,
                  _color,
                   1f);
        transform.DOMoveY(y, 1f);
        //Debug.Log(1);
        yield break;
    }
}
